//
//  UIColor+SJAddition.m
//  D12支付宝初级版本
//
//  Created by 周述坚 on 16/9/15.
//  Copyright © 2016年 周述坚. All rights reserved.
//

#import "UIColor+SJAddition.h"


//给UIColor写一个分类
@implementation UIColor (SJAddition)


/*
 使用16进制数字创建颜色,例如: 0XFF0000  创建红色
 @param  hex  16 进制无符号32位整数
 
 返回:颜色
 */

+ (instancetype)sj_colorWithHex:(uint32_t)hex{
//进行位移运算
    uint8_t r = (hex & 0xff0000) >> 16;
    
    uint8_t g = (hex & 0x00ff00) >> 8;
    
    uint8_t b = (hex & 0x0000ff) ;
    
    return [self sj_colorWithRed:r andGreen:g andBlue:b];

}


//生成随机颜色的方法

+ (instancetype)sj_randomColor{

    return [UIColor sj_colorWithRed:arc4random_uniform(256) andGreen:arc4random_uniform(256) andBlue:arc4random_uniform(256)];

}

/*
 使用R/ G / B数值来创建颜色
 
 */

+ (instancetype)sj_colorWithRed:(uint8_t)red andGreen:(uint8_t)green andBlue:(uint8_t)blue{

    return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0];

}



@end
